<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <button @click="btnClick">按钮</button>
    <hr>
    num1 +1 =num2
    <br>
    {{num1}}+1={{num2}}
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    const app=new Vue({
        el:'#app',
        data:{
            num1:0,
            num2:1
        },
        // 监听器 输入密码时 有状态的变化 只对普通属性监听
        watch: {
            num1(new_value,old_value){
                console.log(new_value,old_value)
                if (new_value!=old_value) {
                    this.num2=new_value+1
                }
            }
        },
        computed: {
            num2(){
                return this.num1+1
            }
        },
        // 方法
        methods: {
            btnClick(){
                ++this.num1
                this.num2=this.num+1
            }
        },
    })
</script>
</body>
</html>